<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\BaseAdminController;
use App\Http\Requests\ProgrammingLanguageRequest;
use App\Models\ProgrammingLanguage;
use App\Models\QueryBuilder;
use Illuminate\Http\Resources\Json\JsonResource;

class ProgrammingLanguageController extends BaseAdminController
{
    //列表
    public function index()
    {
        $data = QueryBuilder::for(ProgrammingLanguage::query())
            ->fields()
            ->filters(['title'])
            ->includes()
            ->sorts()
            ->page();
        return $this->success(JsonResource::collection($data));
    }

    //添加
    public function store(ProgrammingLanguageRequest $request)
    {
        ProgrammingLanguage::query()->create($request->toArray());
        return $this->success();
    }

    //编辑
    public function update(ProgrammingLanguage $programmingLanguage, ProgrammingLanguageRequest $request)
    {
        $programmingLanguage->update($request->toArray());
        return $this->success();
    }

    //删除
    public function destroy(ProgrammingLanguage $programmingLanguage)
    {
        $programmingLanguage->delete();
        return $this->noContent();
    }
}
